<?php
 include "counter2.php";
 $self_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 if (!$limit) {
	$limit = 50;
 }
?>
<?php pagehead("Select some users") ?>
<BODY bgcolor="white">
<?php pagetop("Select some users") ?>

<form action="<?php echo $self_url ?>">
SELECT stuff FROM persons, users, email WHERE persons.f_key = users.f_key
AND email.f_key = users.email AND....

<?php
# SOMETHING in PHP wants to backslash-quote the singlequotes...
$criteria = stripslashes($criteria);
?>
<br>
<textarea name="criteria" rows=5 cols=60>
<?php echo $criteria ?>
</textarea>
<br>
LIMIT <input name="limit" value="<?php echo $limit ?>">
<br>
<input type="submit" value="Search">
<input type="reset" value="Clear">
</form>

<?php
if ($criteria) {
	$search = "select persons.f_key, name, persons.email, city, country, users.state as ustate from persons, users, email where users.f_key = persons.f_key and email.f_key = users.email and $criteria limit $limit";
# print "Search expression is \"$search\"\n";
	$query = mysql_query($search);
	if (!$query) {
		print mysql_error();
		die("Query failed");
	}
	$rows = mysql_num_rows($query);
	if ($rows == 0) {
		print "<p>Nothing found\n";
	} else {
		print "<p>$rows entries found\n";
		if ($rows > 50) {
			print "<br>50 first matches shown\n";
		}
		print "<table border>";
		$counter = 0;
		while ($arr = mysql_fetch_array($query)) {
			print "<tr><td>";
			print "<a href=\"/cgi-bin/adm/display-person.cgi?user=$arr[f_key]\">";
			print $arr[f_key] . "</a>";
			print "<td>" . $arr[name] . "\n";
			print "<td>" . $arr[email] . "\n";
			print "<td>" . $arr[city] . "\n";
			print "<td>" . $arr[country] . "\n";
			print "<td>" . $arr[ustate] . "\n";

			++ $counter;
			if ($counter > 20) {
				break;
			}
		}
		print "</table>\n";
	}
}
?>


<?php pagebottom() ?>
</body>
</html>
